package com.wenmingliang;

import org.junit.Test;

import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;

public class CollectionTest {

    @Test
    public void test1() {
        Collection coll = new ArrayList();
        coll.add(123);
        coll.add(456);
        coll.add(new String("Tome"));
        coll.add(false);
        coll.add(new Person("Jerry",20));

        boolean contains = coll.contains(123);
        System.out.println(contains);
        boolean tome = coll.contains(new String("Tome"));
        System.out.println(tome);

        Collection coll1 = Arrays.asList(123,456);
        System.out.println(coll.containsAll(coll1));

        coll.remove(123);
        coll.remove(new String("Tome"));
        coll.remove(new Person("Jerry", 20));
        System.out.println(coll);
    }

    @Test
    public void test2() {
        Collection coll = new ArrayList();
        coll.add(123);
        coll.add(456);
        coll.add(new String("Tome"));
        coll.add(false);
        coll.add(new Person("Jerry",20));

//        Collection coll2 = Arrays.asList(123,456,789);
//        boolean b = coll.retainAll(coll2);
//        System.out.println(coll);
//        System.out.println(coll2);

        Collection coll1 = new ArrayList();
        coll1.add(123);
        coll1.add(456);
        coll1.add(new String("Tome"));
        coll1.add(false);
        coll1.add(new Person("Jerry",20));
        System.out.println(coll.equals(coll1));
    }

    @Test
    public void test3() {
        Collection coll = new ArrayList();
        coll.add(123);
        coll.add(456);
        coll.add(new String("Tome"));
        coll.add(false);
        coll.add(new Person("Jerry",20));
        System.out.println(coll.hashCode());

        Object[] objects = coll.toArray();
        for (int i = 0; i < objects.length; i++) {
            System.out.println(objects[i]);
        }

        List<String> strings = Arrays.asList(new String[]{"aa", "bb", "cc"});
        System.out.println(strings);
    }
}
